package com.jkoss.wine.shop.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.jkoss.base.controller.BaseController;
import com.jkoss.common.vo.DwzPageBean;
import com.jkoss.wine.shop.entity.MerchantCommonType;
import com.jkoss.wine.shop.entity.MerchantProductPics;
import com.jkoss.wine.shop.service.IMerchantProductPicsService;

/**
 * 前端控制器
 * 
 * @Author Jason
 * @Version 1.0, 2018-09-25
 * @See
 * @Since com.jkoss.wine.shop.controller
 * @Description: TODO
 */
@Controller
@RequestMapping("/shop/merchantProductPics")
public class MerchantProductPicsController extends BaseController {

	@Autowired
	private IMerchantProductPicsService iMerchantProductPicsService;

	/**
	 * 列表
	 * 
	 * @param dwzPageBean
	 * @param map
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/list")
	@RequiresPermissions("/shop/merchantProductPics/list")
	public String list(DwzPageBean dwzPageBean, ModelMap map, HttpServletRequest request, HttpServletResponse response) {
		Page resultPage = iMerchantProductPicsService.selectPage(dwzPageBean.toPage(), null);
		map.put("dwzPageBean", dwzPageBean.toDwzPageBean(resultPage));
		return "shop/merchantProductPics/list";
	}

	/**
	 * 去新增
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/toInsert")
	@RequiresPermissions("/shop/merchantProductPics/toInsert")
	public String toInsert(HttpServletRequest request, HttpServletResponse response) {
		return "shop/merchantProductPics/edit";
	}

	@RequestMapping("/insert")
	@RequiresPermissions("/shop/merchantProductPics/toInsert")
	@ResponseBody
	public Object insert(@Valid MerchantProductPics merchant_product_pics, HttpServletRequest request, HttpServletResponse response) {
		if (iMerchantProductPicsService.insert(merchant_product_pics)) {
			return ajaxSuccess();
		} else {
			return ajaxError();
		}

	}

	/**
	 * 去修改
	 * 
	 * @param id
	 * @param map
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/toUpdate")
	@RequiresPermissions("/shop/merchantProductPics/toUpdate")
	public String toUpdate(String id, ModelMap map, HttpServletRequest request, HttpServletResponse response) {
		map.put("record", iMerchantProductPicsService.selectById(id));
		return "shop/merchantProductPics/edit";
	}

	@RequestMapping("/update")
	@RequiresPermissions("/shop/merchantProductPics/toUpdate")
	@ResponseBody
	public Object update(@Valid MerchantProductPics merchant_product_pics, HttpServletRequest request, HttpServletResponse response) {
		if (iMerchantProductPicsService.updateById(merchant_product_pics)) {
			return ajaxSuccess();
		} else {
			return ajaxError();
		}
	}

	/**
	 * 去删除
	 * 
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("/shop/merchantProductPics/delete")
	@ResponseBody
	public Object delete(String[] id, HttpServletRequest request, HttpServletResponse response) {
		List list = new ArrayList();
		for (String string : id) {
			MerchantProductPics merchantProductPics = new MerchantProductPics();
			merchantProductPics.setMerchantProductId(string);
			// 是否删除：0-未删除、1-已删除、2-不能删除
			list.add(merchantProductPics);
		}
		if (iMerchantProductPicsService.updateBatchById(list)) {
			return ajaxSuccess();
		} else {
			return ajaxError();
		}
	}

}
